/**
 *
 * \file CException.cpp
 * \brief This file contains the CException class implementation.
 * \author Vladimir Klubkov (aka marked)
 *
 * Last changes date:
 * \date 15.03.2011
 *
 * Copyright 2011 Vladimir Klubkov <marked-one@yandex.ru>
 *
 * This file is part of OOXlib.
 *
 * OOXLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * OOXlib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OOXlib; if not, you can try to find  it here:
 * http://www.gnu.org/licenses/gpl.txt
 * or write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "../include/CException.h"

namespace OOXlib {

/**
 * Constructor. Initializes data-members.
 */
CException::CException() : m_Description("EXCEPTION!"), m_iReturnValue(-1) {}
/**
 * Constructor. Initializes data-members.
 * \param File Source code file name.
 * \param iLine Source code line.
 * \param Function Function name.
 */
CException::CException(const ::std::string &File, const int iLine, const ::std::string &Function)
: m_Description("EXCEPTION!"), m_iReturnValue(-1) {
    ::std::ostringstream oss;
    oss << "\nFile: " << File << "\nLine: " << iLine << "\nFunction: " << Function << "\n";
    m_Description += oss.str();
}
/**
 * Constructor. Initializes data-members.
 * \param File Source code file name.
 * \param iLine Source code line.
 * \param Function Function name.
 * \param Description Exception description.
 */
CException::CException(const ::std::string &File, const int iLine, const ::std::string &Function, const ::std::string &Description)
: m_Description("EXCEPTION!"), m_iReturnValue(-1) {
    ::std::ostringstream oss;
    oss << "\nFile: " << File << "\nLine: " << iLine << "\nFunction: " << Function << "\n" << Description;
    m_Description += oss.str();
}
/**
 * Constructor. Initializes data-members.
 * \param File Source code file name.
 * \param iLine Source code line.
 * \param Function Function name.
 * \param Description Exception description.
 * \param iReturnValue Specifies the error code aka retrun value.
 */
CException::CException(const ::std::string &File, const int iLine, const ::std::string &Function, const ::std::string &Description, const int iReturnValue)
: m_Description("EXCEPTION!"), m_iReturnValue(iReturnValue) {
    ::std::ostringstream oss;
    oss << "\nFile: " << File << "\nLine: " << iLine << "\nFunction: " << Function << "\n" << Description;
    m_Description += oss.str();
}
/**
 * Virtual destructor. Does nothing.
 */
CException::~CException() {};
/**
 * Returns a pointer to the description string.
 * \return A pointer to the error description string. This method never returns the empty string.
 */
::std::string CException::Description() const {
    if(m_Description.empty()) {
        return "\n";
    }
    return m_Description + '\n';
}
/**
 * Returns the specified error code. The function name means, that this error code can/must be used as a return value.
 * \return A pointer to the return value.
 */
int CException::ReturnValue() const {
    return m_iReturnValue;
}

} // OOXlib
